package com.itheima.UDPdemo.练习;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class ReceiveMessageDemo {
    public static void main(String[] args) throws IOException {

        DatagramSocket ds=new DatagramSocket(10086);
        byte[] bytes=new byte[1024];
        //第一个是什么数组，第二个是用多长
        DatagramPacket dp=new DatagramPacket(bytes,bytes.length);//每一次都会覆盖

        while (true) {

            ds.receive(dp);

            byte[] bytes1=dp.getData();

            System.out.println(new String(bytes1,0,dp.getLength()));
            System.out.println(dp.getLength());
            System.out.println(dp.getAddress());
            System.out.println(dp.getPort());
        }
        //dp.close;不需要



    }
}
